/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.domain.request;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.kunminx.architecture.domain.message.MutableResult;
import com.kunminx.architecture.domain.message.Result;
import com.nsgf.library.data.api.AccountService;
import com.nsgf.library.data.bean.ClockInBean;
import com.nsgf.library.data.bean.DisplacementBean;
import com.nsgf.library.data.bean.FacilityBean;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.data.bean.MessageBean;
import com.nsgf.library.data.bean.MonitorBean;
import com.nsgf.library.data.bean.ProjectBean;
import com.nsgf.library.data.bean.RepairBean;
import com.nsgf.library.data.bean.TransfusionBean;
import com.nsgf.library.data.bean.User;
import com.nsgf.library.data.bean.UserDataBean;
import com.nsgf.library.data.bean.UserInfo;
import com.nsgf.library.data.bean.VideoListBean;
import com.nsgf.library.data.bean.WareHouseBean;
import com.nsgf.library.data.bean.WaterRecordsBean;
import com.nsgf.library.data.bean.WeatherBean;
import com.nsgf.library.data.bean.WeatherDetailBean;
import com.nsgf.library.data.bean.WorkOrderBean;
import com.nsgf.library.data.bean.WorkOrderDetailBean;
import com.nsgf.library.data.repository.DataRepository;
import com.nsgf.library.data.response.DataResult;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.data.response.ResultSource;
import com.nsgf.library.utils.ToastUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 用户账户 Request
 * <p>
 * TODO tip 1：让 UI 和业务分离，让数据总是从生产者流向消费者
 * <p>
 * UI逻辑和业务逻辑，本质区别在于，前者是数据的消费者，后者是数据的生产者，
 * "领域层组件" 作为数据的生产者，职责应仅限于 "请求调度 和 结果分发"，
 * <p>
 * 换言之，"领域层组件" 中应当只关注数据的生成，而不关注数据的使用，
 * 改变 UI 状态的逻辑代码，只应在表现层页面中编写、在 Observer 回调中响应数据的变化，
 * 将来升级到 Jetpack Compose 更是如此，
 * <p>
 * Activity {
 * onCreate(){
 * vm.livedata.observe { result->
 * panel.visible(result.show ? VISIBLE : GONE)
 * tvTitle.setText(result.title)
 * tvContent.setText(result.content)
 * }
 * }
 * Create by GC at 24/10/26
 */
public class AccountRequester extends Requester implements DefaultLifecycleObserver {

    //TODO tip 3：👆👆👆 让 accountRequest 可观察页面生命周期，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期问题。

    private final MutableResult<DataResult<UserInfo>> tokenResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<UserInfo>>> userResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<UserDataBean>> userDataResult = new MutableResult<>();
    private final MutableResult<DataResult<MessageBean>> messageResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<MessageBean.DataBean>>> messageDetailResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<String>>> src = new MutableResult<>();
    private final MutableResult<DataResult<ClockInBean>> clockInResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<List<ClockInBean.DataBean>>>> videoResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<Object>>> videoSrc = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<List<WorkOrderBean>>>> workOrder = new MutableResult<>();
    private final MutableResult<DataResult<WorkOrderDetailBean>> workOrderDetail = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<WorkOrderDetailBean.FileDto>>> fileInfo = new MutableResult<>();
    private final MutableResult<DataResult<WeatherBean>> weatherDetailResult = new MutableResult<>();
    private final MutableResult<DataResult<ClockInBean>> statisticsResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<ProjectBean>> reservoirResult = new MutableResult<>();


    private final MutableResult<ResponseStatus<UserInfo>> userResultProject = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<VideoListBean>>> reginVideoList = new MutableResult<>();


    private final MutableResult<ResponseStatus<String>> srcSuccess = new MutableResult<>();

    private final MutableResult<ResponseStatus<LibraryInfo>> libraryInfo = new MutableResult<>();
    private final MutableResult<ResponseStatus<WaterRecordsBean>> waterRecords = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<LibraryInfo>>> waterRecordList = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<LibraryInfo>>> rainRecordList = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<LibraryInfo>>> libraryList = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<UserInfo.ProjectListBean>>> projectList = new MutableResult<>();
    private final MutableResult<ResponseStatus<WeatherDetailBean>> weatherDetailBean = new MutableResult<>();

    public MutableResult<DataResult<ClockInBean>> getStatisticsResult() {
        return statisticsResult;
    }

    private final MutableResult<ResponseStatus<List<WareHouseBean>>> wareHouseResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<TransfusionBean>> transfusionResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<String>>> transectNameResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<MonitorBean>> monitorBeanResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<DisplacementBean>>> displacementResult = new MutableResult<>();


    private final MutableResult<ResponseStatus<RepairBean>> repairResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<FacilityBean>>> facilityResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<FacilityBean>> facilityDetailResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<WorkOrderBean>> workOrderDetailResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<Object>> stringResult = new MutableResult<>();

    public MutableResult<ResponseStatus<UserInfo>> getUserResultProject() {
        return userResultProject;
    }

    //TODO tip 4：应顺应 "响应式编程"，做好 "单向数据流" 开发，
    // MutableResult 应仅限 "鉴权中心" 内部使用，且只暴露 immutable Result 给 UI 层，
    // 通过 "读写分离" 实现数据从 "领域层" 到 "表现层" 的单向流动，

    //如这么说无体会，详见《吃透 LiveData 本质，享用可靠消息鉴权机制》解析。
    //https://xiaozhuanlan.com/topic/6017825943

    public Result<DataResult<UserInfo>> getTokenResult() {
        return tokenResult;
    }

    public Result<DataResult<ResponseStatus<UserInfo>>> getUserResult() {
        return userResult;
    }

    public Result<DataResult<MessageBean>> getMessageResult() {
        return messageResult;
    }

    public Result<DataResult<ResponseStatus<MessageBean.DataBean>>> getMessageDetailResult() {
        return messageDetailResult;
    }

    public Result<DataResult<ResponseStatus<String>>> getSrc() {
        return src;
    }

    public Result<DataResult<ClockInBean>> getClockInResult() {
        return clockInResult;
    }

    public MutableResult<DataResult<ResponseStatus<List<ClockInBean.DataBean>>>> getVideoResult() {
        return videoResult;
    }

    public MutableResult<DataResult<ResponseStatus<Object>>> getVideoSrc() {
        return videoSrc;
    }


    //TODO tip 5：模拟可取消的登录请求：
    //
    // 配合可观察页面生命周期的 accountRequest，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期的问题。

    public Disposable mDisposable;

    //TODO tip 6: requester 作为数据的生产者，职责应仅限于 "请求调度 和 结果分发"，
    //
    // 换言之，此处只关注数据的生成和回推，不关注数据的使用，
    // 改变 UI 状态的逻辑代码，只应在表现层页面中编写，例如 Jetpack Compose 的使用，

    public void requestLogin(User user) {

        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("username", user.getName());
        jsonObject.addProperty("password", user.getPassword());
        RequestBody requestBody = RequestBody.create(mediaType, jsonObject.toString());

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).login(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<UserDataBean>>(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {
                userDataResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                userDataResult.postValue(new ResponseStatus(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });

        DataRepository.getInstance().subscribe(observable, observer);

//        DataRepository.getInstance().login(user).subscribe(new Observer<DataResult<UserDataBean>>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//                mDisposable = d;
//            }
//
//            @Override
//            public void onNext(DataResult<UserDataBean> dataResult) {
//
//                userDataResult.postValue(dataResult);
//
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                userResult.postValue(new DataResult<>(null,
//                        new ResponseStatus(0, false, ResultSource.NETWORK)));
//            }
//
//            @Override
//            public void onComplete() {
//                mDisposable = null;
//            }
//        });
    }

    // 获取到请求类型（MediaType）
    private static MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");


    /**
     * 版本更新
     */
    public void getVersion() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getVersion("0", "VERSION");
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<LibraryInfo>>(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {
                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(0, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);
    }

    public void updatePassWord(String oldPwd, String oldPwd2, String newPwd, String newPwd2) {

        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("oldPwd", oldPwd);
        jsonObject.addProperty("oldPwd2", oldPwd2);
        jsonObject.addProperty("newPwd", newPwd);
        jsonObject.addProperty("newPwd2", newPwd2);
        RequestBody requestBody = RequestBody.create(mediaType, jsonObject.toString());

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).updatePassWord(oldPwd, newPwd);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                if (200 == dataResult.getResponseCode()) {
                    srcSuccess.postValue(dataResult);
                } else ToastUtils.showShortToast(dataResult.getMsg());
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(0, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);
    }

    public void getNewLoginInfo() {

        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<UserInfo>>(new HttpOnNextListener<ResponseStatus<UserInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<UserInfo> dataResult) {

                if (200 == dataResult.getResponseCode()) {
                    userResultProject.postValue(dataResult);
                } else {
                    userResultProject.postValue(new ResponseStatus<>(0, true, dataResult.getMsg()));
                    ToastUtils.showShortToast(dataResult.getMsg());
                }
            }

            @Override
            public void onFail(String e) {
                userResultProject.postValue(new ResponseStatus<>(0, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getNewLoginInfo();
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void setTokenResult() {

        DataRepository.getInstance().getLoginInfo().subscribe(new Observer<DataResult<ResponseStatus<UserInfo>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<UserInfo>> dataResult) {

                if (null != dataResult.getResult())
                    if (null != dataResult.getResult().getData().getProjectList()) {
                        if (!dataResult.getResult().getData().getProjectList().isEmpty()) {
                            for (int i = 0; i < dataResult.getResult().getData().getProjectList().size(); i++) {
                                if (1 == dataResult.getResult().getData().getProjectList().get(i).getIsExperiment()) {
                                    dataResult.getResult().getData().setProjectCode(dataResult.getResult().getData().getProjectList().get(i).getProjectCode());
                                    UserInfo.getInstance().setProjectName(dataResult.getResult().getData().getProjectList().get(i).getProjectName());
                                    UserInfo.getInstance().setAppLogo(dataResult.getResult().getData().getAppCfg().getAppLogo());
                                    break;
                                }
                            }
                        }
                    }

                userResult.postValue(dataResult);

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void getMessageDetail(String id, boolean warning) {

        DataRepository.getInstance().getMessageDetail(id, warning).subscribe(new Observer<DataResult<ResponseStatus<MessageBean.DataBean>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<MessageBean.DataBean>> dataResult) {
                messageDetailResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                messageDetailResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });
        ;

    }

    public void getUnreadCount(String projectCode, boolean type) {


        DataRepository.getInstance().getUnreadCount(projectCode, type).subscribe(new Observer<DataResult<ResponseStatus<MessageBean.DataBean>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<MessageBean.DataBean>> dataResult) {
                messageDetailResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                messageDetailResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    public void setClearMessage(int type, String projectCode) {

        String clearType;
        switch (type) {
            case 1:
                clearType = "message.type.1";
                break;
            case 2:
                clearType = "message.type.2";
                break;
            default:
                clearType = "";
                break;
        }
        DataRepository.getInstance().setClearMessage(clearType, projectCode).subscribe(new Observer<DataResult<ResponseStatus<String>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<String>> dataResult) {
                src.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                messageDetailResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * @param type
     * @param projectCode
     */
    public void setClearWarningMessage(int type, String projectCode) {

        String clearType;
        switch (type) {
            case 1:
                clearType = "warn.type.1";
                break;
            case 2:
                clearType = "warn.type.2";
                break;
            case 3:
                clearType = "warn.type.3";
                break;
            default:
                clearType = "";
                break;
        }
        DataRepository.getInstance().setClearWarningMessage(clearType, projectCode).subscribe(new Observer<DataResult<ResponseStatus<String>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<String>> dataResult) {
                src.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                src.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * @param projectCode
     */
    public void sameDayClockInDetail(String projectCode) {

        DataRepository.getInstance().sameDayClockInDetail(projectCode).subscribe(new Observer<DataResult<ClockInBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ClockInBean> dataResult) {
                clockInResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                clockInResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * @param projectCode
     */

    public void punchTheClock(String projectCode) {

        DataRepository.getInstance().punchTheClock(projectCode).subscribe(new Observer<DataResult<ResponseStatus<String>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<String>> dataResult) {

                src.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                src.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param projectCode
     * @param yearMonth
     */
    public void punchSummary(String projectCode, String yearMonth) {

        DataRepository.getInstance().punchSummary(projectCode, yearMonth).subscribe(new Observer<DataResult<ClockInBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ClockInBean> dataResult) {
                clockInResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                clockInResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param projectCode
     * @param videoName
     */
    public void videoList(String projectCode, String videoName) {

        DataRepository.getInstance().videoList(projectCode, videoName).subscribe(new Observer<DataResult<ResponseStatus<List<ClockInBean.DataBean>>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<List<ClockInBean.DataBean>>> dataResult) {
                videoResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                videoResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param deviceCode
     * @param callingMode
     */
    public void videoInfo(String deviceCode, String channelId, String callingMode) {

        DataRepository.getInstance().videoInfo(deviceCode, channelId, callingMode).subscribe(new Observer<DataResult<ResponseStatus<Object>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<Object>> dataResult) {

                videoSrc.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                videoSrc.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * @param orderCode
     */
    public void patrolDetail(String orderCode) {

        DataRepository.getInstance().patrolDetail(orderCode).subscribe(new Observer<DataResult<WorkOrderDetailBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<WorkOrderDetailBean> dataResult) {

                workOrderDetail.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                workOrderDetail.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param path
     */
    public void uploadFile(String path) {

        DataRepository.getInstance().uploadFile(path).subscribe(new Observer<DataResult<ResponseStatus<WorkOrderDetailBean.FileDto>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<WorkOrderDetailBean.FileDto>> dataResult) {

                fileInfo.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                workOrderDetail.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param jsonObject
     */
    public void handleWorkOrder(JSONObject jsonObject) {

        DataRepository.getInstance().handleWorkOrder(jsonObject).subscribe(new Observer<DataResult<ResponseStatus<String>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<String>> dataResult) {

                src.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                workOrderDetail.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * @param jsonObject
     */
    public void reviewWorkOrder(JsonObject jsonObject) {

        DataRepository.getInstance().reviewWorkOrder(jsonObject).subscribe(new Observer<DataResult<ResponseStatus<String>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ResponseStatus<String>> dataResult) {

                src.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                workOrderDetail.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * @param dictCode
     */
    public void getDictItems(String dictCode) {

        DataRepository.getInstance().getDictItems(dictCode).subscribe(new Observer<DataResult<WeatherBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<WeatherBean> dataResult) {

                weatherDetailResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                weatherDetailResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }


    /**
     * 消息统计
     *
     * @param projectCode
     */
    public void getStatistics(String projectCode) {

        DataRepository.getInstance().getStatistics(projectCode).subscribe(new Observer<DataResult<ClockInBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mDisposable = d;
            }

            @Override
            public void onNext(DataResult<ClockInBean> dataResult) {

                statisticsResult.postValue(dataResult);
            }

            @Override
            public void onError(Throwable e) {
                statisticsResult.postValue(new DataResult<>(null,
                        new ResponseStatus(0, false, ResultSource.NETWORK)));
            }

            @Override
            public void onComplete() {
                mDisposable = null;

            }
        });

    }

    /**
     * 水库详情
     *
     * @param projectCode
     */
    public void reservoirInfo(String projectCode) {

        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<ProjectBean>>(new HttpOnNextListener<ResponseStatus<ProjectBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProjectBean> dataResult) {

                if (200 == dataResult.getResponseCode()) {
                    reservoirResult.postValue(dataResult);
                } else ToastUtils.showShortToast(dataResult.getMsg());

            }

            @Override
            public void onFail(String e) {
                ToastUtils.showLongToast(e);

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).reservoirInfo(projectCode);
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     * @param patrolType
     */
    public void sameDayPatrolTask(String patrolType) {
        DataRepository.getInstance()
                .sameDayPatrolTask(patrolType)
                .subscribe(new io.reactivex.Observer<DataResult<ResponseStatus<List<WorkOrderBean>>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mDisposable = d;
                    }

                    @Override
                    public void onNext(DataResult<ResponseStatus<List<WorkOrderBean>>> dataResult) {
                        workOrder.postValue(dataResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        workOrder.postValue(new DataResult<>(null,
                                new ResponseStatus(0, false, ResultSource.NETWORK)));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
    }


    /**
     * @param videoName
     */
    public void getReginVideoList(String videoName) {


        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getReginVideoList(videoName);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<VideoListBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<VideoListBean>> dataResult) {

                reginVideoList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                reginVideoList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 大坝巡查动态统计
     *
     * @param startDate
     * @param endDate
     */
    public void damDynamicsStatistics(String startDate, String endDate) {


        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).damDynamicsStatistics(startDate, endDate);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                libraryList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                libraryList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 按天查询动态
     *
     * @param date
     */
    public void damDailyDynamics(String date) {


        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).damDailyDynamics(date);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                libraryList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                libraryList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * @param projectCode
     * @param startTime
     * @param endTime
     */
    public void regimenInfo(String projectCode, String startTime, String endTime) {

        Observable observable = DataRepository.getRetrofitInstance()
                .create(AccountService.class).regimenInfo(projectCode,
                        startTime,
                        endTime);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<WaterRecordsBean>>() {
            @Override
            public void onSuccess(ResponseStatus<WaterRecordsBean> dataResult) {

                waterRecords.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                waterRecords.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getReservoirByName(String projectName) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getReservoirByName(projectName);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<UserInfo.ProjectListBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<UserInfo.ProjectListBean>> dataResult) {

                projectList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                projectList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getPictureDetails(String projectCode) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getPictureDetails(projectCode);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProjectBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProjectBean> dataResult) {

                reservoirResult.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                reservoirResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getRainMonitoringList(String projectName) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getRainMonitoringList(projectName);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                rainRecordList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                rainRecordList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getWaterMonitoringList(String projectName) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getWaterMonitoringList(projectName);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                waterRecordList.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                waterRecordList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     * 雨情监测详情
     *
     * @param projectCode 水库code
     * @param startTime   开始时间
     * @param endTime     结束时间
     */
    public void getMonitorRainDetails(String projectCode, String startTime, String endTime) {
        JsonObject params = new JsonObject();
        params.addProperty("facilityType", "water.obj.type.9");//后台给的固定值
        params.addProperty("projectCode", projectCode);
        params.addProperty("startTime", startTime);
        params.addProperty("endTime", endTime);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getMonitorRainDetails(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<WaterRecordsBean>>() {
            @Override
            public void onSuccess(ResponseStatus<WaterRecordsBean> dataResult) {

                waterRecords.postValue(dataResult);

            }

            @Override
            public void onFail(String e) {
                waterRecords.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * @param storeName
     */
    public void getStore(String storeName) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getStore(storeName);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<WareHouseBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<WareHouseBean>> dataResult) {

                wareHouseResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                wareHouseResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * @param projectCode
     * @param gateType
     */
    public void realTimeWorkConditions(String projectCode, String gateType) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).realTimeWorkConditions(projectCode, gateType);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                libraryList.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryList.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void taskPlanListId(String projectCode, int year) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).taskPlanListId(projectCode, year, 1, 10);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void taskPlanDetail(String id, MutableResult<ResponseStatus<LibraryInfo>> taskDetailResult) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).taskPlanDetail(id);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {


                taskDetailResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                taskDetailResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryWeatherForecast() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).queryWeatherForecast();
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<WeatherDetailBean>>() {
            @Override
            public void onSuccess(ResponseStatus<WeatherDetailBean> dataResult) {


                weatherDetailBean.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                weatherDetailBean.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 渗流监测
     *
     * @param projectCode
     * @param startTime
     * @param endTime
     */
    public void seepageFlowList(String projectCode, String startTime, String endTime) {

        JsonObject params = new JsonObject();
        params.addProperty("projectCode", projectCode);
        params.addProperty("startTime", startTime);
        params.addProperty("endTime", endTime);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).seepageFlowList(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<TransfusionBean>>() {
            @Override
            public void onSuccess(ResponseStatus<TransfusionBean> dataResult) {

                transfusionResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                transfusionResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 渗压断面
     */
    public void getTransectName(String projectCode) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getTransectName(projectCode);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<String>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<String>> dataResult) {

                transectNameResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                transectNameResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void analysis(String projectCode, String transectName, String startDate, String endDate) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .analysis(projectCode, transectName, startDate, endDate);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<TransfusionBean>>() {
            @Override
            public void onSuccess(ResponseStatus<TransfusionBean> dataResult) {

                transfusionResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                transfusionResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     *
     * @param type 0维修 1养护
     *             **/
    public void getRepairList(JsonObject params, int type) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable;
        if (type == 0)
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getRepairList(requestBody);
        else
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getNurtureList(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<RepairBean>>() {
            @Override
            public void onSuccess(ResponseStatus<RepairBean> dataResult) {

                repairResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                repairResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getRepairInfo(int type, String id) {
        Observable observable;
        if (type == 0)
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getRepairInfo(id);
        else
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getNurtureInfo(id);

        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<RepairBean>>() {
            @Override
            public void onSuccess(ResponseStatus<RepairBean> dataResult) {

                repairResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                repairResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 获取水库注册信息
     * @param projectCode
     */
    public void getRegisterInfo(String projectCode) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getRegisterInfo(projectCode, 1, 1);

        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 获取位移监测
     * @param projectCode
     * @param monitorObj
     * @param monitorType
     */
    public void getSectionTm(String projectCode, String monitorObj, String monitorType) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSectionTm(projectCode, monitorObj, monitorType);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<MonitorBean>>() {
            @Override
            public void onSuccess(ResponseStatus<MonitorBean> dataResult) {

                monitorBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                monitorBeanResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 位移监测详情数据
     * @param params
     */

    public void getDisplacementDist(String params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getDisplacementDist(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<DisplacementBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<DisplacementBean>> dataResult) {

                displacementResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                displacementResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getDisplacementDist(JsonObject params) {
        getDisplacementDist(params.toString());
    }


    /**
     *
     * @param params
     */
    public void getProcessLine(String params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getProcessLine(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<Object>>() {
            @Override
            public void onSuccess(ResponseStatus<Object> dataResult) {

                stringResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                stringResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getGNSSDisplacementDist(String params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getGNSSDisplacementDist(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<DisplacementBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<DisplacementBean>> dataResult) {

                displacementResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                displacementResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getGNSSProcessLine(String params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getGNSSProcessLine(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<Object>>() {
            @Override
            public void onSuccess(ResponseStatus<Object> dataResult) {

                stringResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                stringResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     *
     * @param params
     */
    public void setCreateWord(JsonObject params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .setCreateWord(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     * 水库建筑物列表
     * @param projectCode
     */
    public void facilityList(String projectCode) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .facilityList(projectCode);

        BaseHttpObserver observer =
                new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<FacilityBean>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<FacilityBean>> dataResult) {

                        facilityResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        facilityResult.postValue(new ResponseStatus<>(0, false, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }

                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 建筑物详情
     * @param facilityCode
     * @param type
     */
    public void facilityDetail(String facilityCode, String type) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .facilityDetail(facilityCode, type);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<FacilityBean>>() {
            @Override
            public void onSuccess(ResponseStatus<FacilityBean> dataResult) {

                facilityDetailResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                facilityDetailResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     *
     * @param id
     * @param type
     */
    public void workOrderDetail(String id, String type) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .workOrderDetail(id, type);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<WorkOrderBean>>() {
            @Override
            public void onSuccess(ResponseStatus<WorkOrderBean> dataResult) {

                workOrderDetailResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                workOrderDetailResult.postValue(new ResponseStatus<>(0, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void cancelLogin() {
        if (mDisposable != null && !mDisposable.isDisposed()) {
            mDisposable.dispose();
            mDisposable = null;
        }
    }

    //TODO tip 7：让 accountRequest 可观察页面生命周期，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期问题。


    @Override
    public void onStop(@NonNull @NotNull LifecycleOwner owner) {
        cancelLogin();
    }

    public MutableResult<DataResult<ResponseStatus<List<WorkOrderBean>>>> getWorkOrder() {
        return workOrder;
    }

    public MutableResult<DataResult<WorkOrderDetailBean>> getWorkOrderDetail() {
        return workOrderDetail;
    }

    public MutableResult<DataResult<ResponseStatus<WorkOrderDetailBean.FileDto>>> getFileInfo() {
        return fileInfo;
    }

    public MutableResult<DataResult<WeatherBean>> getWeatherDetailResult() {
        return weatherDetailResult;
    }

    public MutableResult<ResponseStatus<ProjectBean>> getReservoirResult() {
        return reservoirResult;
    }

    public MutableResult<ResponseStatus<UserDataBean>> getUserDataResult() {
        return userDataResult;
    }

    public MutableResult<ResponseStatus<String>> getSrcSuccess() {
        return srcSuccess;
    }

    public MutableResult<ResponseStatus<LibraryInfo>> getLibraryInfo() {
        return libraryInfo;
    }

    public MutableResult<ResponseStatus<List<VideoListBean>>> getReginVideoList() {
        return reginVideoList;
    }

    public MutableResult<ResponseStatus<List<LibraryInfo>>> getLibraryList() {
        return libraryList;
    }

    public MutableResult<ResponseStatus<WaterRecordsBean>> getWaterRecords() {
        return waterRecords;
    }

    public MutableResult<ResponseStatus<List<UserInfo.ProjectListBean>>> getProjectList() {
        return projectList;
    }

    public MutableResult<ResponseStatus<List<LibraryInfo>>> getWaterRecordList() {
        return waterRecordList;
    }

    public MutableResult<ResponseStatus<List<LibraryInfo>>> getRainRecordList() {
        return rainRecordList;
    }

    public MutableResult<ResponseStatus<List<WareHouseBean>>> getWareHouseResult() {
        return wareHouseResult;
    }

    public MutableResult<ResponseStatus<WeatherDetailBean>> getWeatherDetailBean() {
        return weatherDetailBean;
    }

    public MutableResult<ResponseStatus<TransfusionBean>> getTransfusionResult() {
        return transfusionResult;
    }

    public MutableResult<ResponseStatus<List<String>>> getTransectNameResult() {
        return transectNameResult;
    }

    public MutableResult<ResponseStatus<RepairBean>> getRepairResult() {
        return repairResult;
    }

    public MutableResult<ResponseStatus<MonitorBean>> getMonitorBeanResult() {
        return monitorBeanResult;
    }

    public MutableResult<ResponseStatus<List<DisplacementBean>>> getDisplacementResult() {
        return displacementResult;
    }

    public MutableResult<ResponseStatus<Object>> getStringResult() {
        return stringResult;
    }

    public MutableResult<ResponseStatus<List<FacilityBean>>> getFacilityResult() {
        return facilityResult;
    }

    public MutableResult<ResponseStatus<FacilityBean>> getFacilityDetailResult() {
        return facilityDetailResult;
    }

    public MutableResult<ResponseStatus<WorkOrderBean>> getWorkOrderDetailResult() {
        return workOrderDetailResult;
    }
}
